package com.jboost.modules.app.service.strategry.pdm;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jboost.common.constant.enums.OpEnum;
import com.jboost.common.util.HttpRestUtils;
import com.jboost.common.util.JSONUtil;
import com.jboost.modules.app.constant.BanDanB;
import com.jboost.modules.app.constant.BanDanC;
import com.jboost.modules.app.constant.BaseResult;
import com.jboost.modules.app.dto.*;
import com.jboost.modules.app.dto.resp.BDCB;
import com.jboost.modules.app.dto.resp.BdDy;
import com.jboost.modules.app.dto.resp.BdSJ;
import com.jboost.modules.app.service.strategry.common.AbstractJdy;
import com.jboost.modules.app.util.JdyFileUtils;
import com.jboost.modules.app.util.RefelctUtils;
import com.jboost.modules.system.entity.DpBanDan;
import com.jboost.modules.system.entity.PdmBom;
import com.jboost.modules.system.mapper.DpBanDanMapper;
import com.jboost.modules.system.mapper.PdmBomMapper;
import com.qiniu.util.Json;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.jboost.modules.app.util.JdyFileUtils.UUIDS;

@Service(value = "PdmBanDanQuery")
@Slf4j
public class PdmBanDanQuery extends AbstractJdy<JSONObject, DpBanDan, DpBanDanMapper, DpBanDan>  {
    @Autowired
    DpBanDanMapper dpBanDanMapper;
    public String getFormId1() {
        //651d5873fc1c1164757ca231
        return "651d5873fc1c1164757ca231";
    }
   //651fbb02391f2adff5ba5fd4
    public String getFormId2() {
        return "651fbb02391f2adff5ba5fd4";
    }

    public HttpHeaders getJdyHeaders(){
        HttpHeaders jdyHeaders = new HttpHeaders();
        jdyHeaders.set("Authorization","Bearer "+ "j2tq9lljcelsqTPZnbr36USxr6yZWsHu");
        return jdyHeaders;
    }

    public String getAppId() {
        return "64e1f2d0d8b6100009e88053";
    }




    public BaseResult<DpBanDan> invokeStrategy(JSONObject jsonObject) throws Exception {
        
        com.jboost.modules.app.dto.DpBanDan.DataBean data = jsonObject.getObject("data", com.jboost.modules.app.dto.DpBanDan.DataBean.class);
        try {
            System.out.println("111111");
            String op = jsonObject.getString("op");
            UUIDS.set(UUID.randomUUID().toString());
//            if (Objects.equals(op, OpEnum.DATA_CREATE.getOp())){
//                updateCdData(data);
//            } else if (Objects.equals(op, OpEnum.DATA_UPDATE.getOp())) {
//                updateCdData(data);
//            } else if (Objects.equals(op, OpEnum.DATA_REMOVE.getOp())){
//                delCdData(data);
//            }
//            UUIDS.set(UUID.randomUUID().toString());
            com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean creator = data.getCreator();
            com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean updater = data.getUpdater();
            if (creator.getName().equals("moodytiger") || updater.getName().equals("moodytiger")){
                return BaseResult.success();
            }
            if (Objects.equals(op, OpEnum.DATA_CREATE.getOp()) || Objects.equals(op, OpEnum.DATA_UPDATE.getOp())){
                insertBdData(data);
            }
            UUIDS.remove();
            return BaseResult.success();
        }catch (Exception exception){

            System.out.println(1);

        }
        return BaseResult.success();
    }

    private void insertBdData(com.jboost.modules.app.dto.DpBanDan.DataBean data) {
        List<PdmBanDanB.DataBean> dataBeans = buildB(data);
        Map<String, PdmBanDanB.DataBean> dataBeanMap = dataBeans.stream().collect(Collectors.toMap(e -> String.valueOf(e.get_widget_1695639159463().get("value")) + String.valueOf(e.get_widget_1711015798639().get("value")), Function.identity(), (a, b) -> a));
        List<PdmBanDanB.DataBean> collect = dataBeanMap.values().stream().filter(e -> {
            String wlbm = (String) e.get_widget_1695639159463().get("value");
            String ysdm = (String) e.get_widget_1711015798639().get("value");
            JdyReq jdyReq = new JdyReq();
            jdyReq.setApp_id(getAppId());
            jdyReq.setEntry_id(getFormId1());
            jdyReq.setLimit(100);
            jdyReq.setFields(Arrays.asList("_widget_1695639159463", "_widget_1711015798639", "_widget_1695639321594"));
            JdyReq.FilterBean filterBean = new JdyReq.FilterBean();
            filterBean.setRel("and");
            List<JdyReq.FilterBean.CondBean> cond = new ArrayList<>();
            JdyReq.FilterBean.CondBean a = new JdyReq.FilterBean.CondBean();
            a.setField("_widget_1695639159463");
            a.setType("text");
            a.setMethod("eq");
            a.setValue(Arrays.asList(wlbm));
            cond.add(a);
            JdyReq.FilterBean.CondBean a1 = new JdyReq.FilterBean.CondBean();
            a1.setField("_widget_1711015798639");
            a1.setType("text");
            a1.setMethod("eq");
            a1.setValue(Arrays.asList(ysdm));
            cond.add(a1);
            JdyReq.FilterBean.CondBean a2 = new JdyReq.FilterBean.CondBean();
            a2.setField("_widget_1695639321594");
            a2.setType("text");
            a2.setMethod("in");
            a2.setValue(Arrays.asList("正常开发","外协跟进"));
            cond.add(a2);
            filterBean.setCond(cond);
            jdyReq.setFilter(filterBean);
            try {
                String s = jdyQueryAll(jdyReq);
                JSONArray jsonArray = (JSONArray) JSONUtil.fromJson(s, HashMap.class).get("data");
                return jsonArray.size() <= 0;
            } catch (IOException ex) {
                return false;
            }
        }).map(e1 -> {
            String wlbm = (String) e1.get_widget_1695639159463().get("value");
            String wldl = (String) e1.get_widget_1695641447640().get("value");
            if (Objects.equals(wldl, "面料")) {
                JdyReq jdyReq = new JdyReq();
                jdyReq.setApp_id(getAppId());
                jdyReq.setEntry_id("64d9c508130ea8000a6f48bd");
                jdyReq.setLimit(100);
                jdyReq.setFields(Arrays.asList(""));
                JdyReq.FilterBean filterBean = new JdyReq.FilterBean();
                filterBean.setRel("and");
                List<JdyReq.FilterBean.CondBean> cond = new ArrayList<>();
                JdyReq.FilterBean.CondBean a = new JdyReq.FilterBean.CondBean();
                a.setField("b");
                a.setType("text");
                a.setMethod("eq");
                a.setValue(Arrays.asList(wlbm));
                cond.add(a);
                filterBean.setCond(cond);
                jdyReq.setFilter(filterBean);
                try {
                    String s = jdyQueryAll(jdyReq);
                    JSONArray jsonArray = (JSONArray) JSONUtil.fromJson(s, HashMap.class).get("data");
                    if (jsonArray.size() > 0) {
                        PdmMl.DataBean dataBean = JSONUtil.fromJson(JSONUtil.toJson(jsonArray.get(0)), PdmMl.DataBean.class);
                        e1.set_widget_1696422046844(getParaMap(dataBean.get_widget_1695706945988()));
                        e1.set_widget_1699184154164(getParaMap(dataBean.get_widget_1696304422264()));
                        e1.set_widget_1696422046845(getParaMap(dataBean.get_widget_1695706945986()));
                        e1.set_widget_1696422046846(getParaMap(dataBean.get_widget_1695706945987()));
                        e1.set_widget_1696666156509(getParaMap(dataBean.get_widget_1696665662629()));
                    }
                } catch (IOException ex) {

                }
            } else {
                JdyReq jdyReq = new JdyReq();
                jdyReq.setApp_id(getAppId());
                jdyReq.setEntry_id("64dc607b532d980008a75f13");
                jdyReq.setLimit(100);
                jdyReq.setFields(Arrays.asList(""));
                JdyReq.FilterBean filterBean = new JdyReq.FilterBean();
                filterBean.setRel("and");
                List<JdyReq.FilterBean.CondBean> cond = new ArrayList<>();
                JdyReq.FilterBean.CondBean a = new JdyReq.FilterBean.CondBean();
                a.setField("b");
                a.setType("text");
                a.setMethod("eq");
                a.setValue(Arrays.asList(wlbm));
                cond.add(a);
                filterBean.setCond(cond);
                jdyReq.setFilter(filterBean);
                try {
                    String s = jdyQueryAll(jdyReq);
                    JSONArray jsonArray = (JSONArray) JSONUtil.fromJson(s, HashMap.class).get("data");
                    if (jsonArray.size() > 0) {
                        PdmFl.DataBean dataBean = JSONUtil.fromJson(JSONUtil.toJson(jsonArray.get(0)), PdmFl.DataBean.class);
                        e1.set_widget_1696422046844(getParaMap(dataBean.get_widget_1692333142509()));
                        e1.set_widget_1699184154164(getParaMap(dataBean.get_widget_1696305650913()));
                        e1.set_widget_1696422046845(getParaMap(dataBean.get_widget_1692333142512()));
                        e1.set_widget_1696422046846(getParaMap(dataBean.get_widget_1692333142513()));
                        e1.set_widget_1696666156509(getParaMap(dataBean.get_widget_1696665695883()));
                    }
                } catch (IOException ex) {

                }
            }
            return e1;

        }).collect(Collectors.toList());
        collect.forEach(e2->{
            try {
                jdyCreate1(e2);
            } catch (IOException e) {

            }
        });
    }

    private void delCdData(com.jboost.modules.app.dto.DpBanDan.DataBean data) {
        List<DpBanDan> dpBanDans = dpBanDanMapper.selectList(Wrappers.lambdaQuery(DpBanDan.class).eq(DpBanDan::getBdid, data.get_id()));
        delCBdDataByDB(dpBanDans);
    }

    private void delCBdDataByDB(List<DpBanDan> dpBanDans) {
        dpBanDans.forEach(e->{
            PdmBanDanC.DataBeanCanCel dataBeanCanCel = new PdmBanDanC.DataBeanCanCel();
            dataBeanCanCel.set_widget_1695300314310(getParaMap("已取消"));
            try {
                jdyUpdate2(e.getDataId(),dataBeanCanCel);
            } catch (IOException ex) {
            }
        });
    }

    private void updateCdData(com.jboost.modules.app.dto.DpBanDan.DataBean data) throws Exception {
        //buildC(data);
        List<PdmBanDanC.DataBean> dataBeans = buildC(data);
        List<DpBanDan> dpBanDans = dpBanDanMapper.selectList(Wrappers.lambdaQuery(DpBanDan.class).eq(DpBanDan::getBdid, data.get_id()));
        Map<String, DpBanDan> danMap = dpBanDans.stream().collect(Collectors.toMap(DpBanDan::getUuid, Function.identity(), (a, b) -> a));
        Set<String> uuids = dpBanDans.stream().map(DpBanDan::getUuid).collect(Collectors.toSet());
        //新增
        dataBeans.stream().filter(e1->!uuids.contains(e1.get_widget_1695299408498().get("value"))).forEach(e-> {
                    try {

                        JdyReq jdyReq = new JdyReq();
                        jdyReq.setApp_id(getAppId());
                        jdyReq.setEntry_id("651fbb02391f2adff5ba5fd4");
                        jdyReq.setLimit(100);
                        jdyReq.setFields(Arrays.asList(""));
                        JdyReq.FilterBean filterBean = new JdyReq.FilterBean();
                        filterBean.setRel("and");
                        List<JdyReq.FilterBean.CondBean> cond = new ArrayList<>();
                        JdyReq.FilterBean.CondBean a = new JdyReq.FilterBean.CondBean();
                        a.setField("_widget_1695299408498");
                        a.setType("text");
                        a.setMethod("eq");
                        a.setValue(Arrays.asList(String.valueOf(e.get_widget_1695299408498().get("value"))));
                        JdyReq.FilterBean.CondBean a1 = new JdyReq.FilterBean.CondBean();
                        cond.add(a);
                        a1.setField("_widget_1695300314310");
                        a1.setType("text");
                        a1.setMethod("eq");
                        a1.setValue(Arrays.asList("正常"));
                        cond.add(a1);
                        filterBean.setCond(cond);
                        jdyReq.setFilter(filterBean);
                        String s1 = jdyQueryAll(jdyReq);
                        JSONArray jsonArray = (JSONArray) JSONUtil.fromJson(s1, HashMap.class).get("data");
                        if (jsonArray.size() <= 0) {
                            String s = jdyCreate2(e);
                            String id = (String) JSONUtil.fromJson(JSONUtil.toJson(JSONUtil.fromJson(s, HashMap.class).get("data")), HashMap.class).get("_id");
                            DpBanDan dpBanDan = new DpBanDan();
                            dpBanDan.setUuid((String) e.get_widget_1695299408498().get("value"));
                            dpBanDan.setBdid(data.get_id());
                            dpBanDan.setType(2);
                            dpBanDan.setDataId(id);
                            dpBanDanMapper.insert(dpBanDan);
                        }else {
                            JSONObject jsonObject = (JSONObject) jsonArray.get(0);
                            jdyUpdate2(jsonObject.getString("_id"),e);
                        }
                    } catch (IOException ex) {
                        System.out.println(1);
                    }
                }
        );
        //修改
        dataBeans.stream().filter(e1->uuids.contains(e1.get_widget_1695299408498().get("value"))).forEach(e->{
            try {
                DpBanDan dpBanDan = danMap.get(e.get_widget_1695299408498().get("value"));
                jdyUpdate2(dpBanDan.getDataId(),e);
            } catch (IOException ex) {
                System.out.println(1);
            }
        });

        //设置为取消
//        Set<String> value = dataBeans.stream().map(e -> (String)e.get_widget_1695299408498().get("value")).collect(Collectors.toSet());
//        delCBdDataByDB(dpBanDans.stream().filter(e->!value.contains(e.getUuid())).collect(Collectors.toList()));
    }

    private void insertCdData(com.jboost.modules.app.dto.DpBanDan.DataBean data) throws Exception {
        //buildC(data);
        List<PdmBanDanC.DataBean> dataBeans = buildC(data);
        dataBeans.forEach(e->{
            try {
                String s = jdyCreate2(e);
                String id = (String)JSONUtil.fromJson(JSONUtil.toJson(JSONUtil.fromJson(s, HashMap.class).get("data")), HashMap.class).get("_id");
                DpBanDan dpBanDan = new DpBanDan();
                dpBanDan.setUuid((String) e.get_widget_1695299408498().get("value"));
                dpBanDan.setBdid(data.get_id());
                dpBanDan.setType(2);
                dpBanDan.setDataId(id);
                dpBanDanMapper.insert(dpBanDan);
            } catch (IOException ex) {
               System.out.println(1);
            }
        });
    }

    private List<com.jboost.modules.app.dto.PdmBanDanB.DataBean> buildB(com.jboost.modules.app.dto.DpBanDan.DataBean data) {
        List<PdmBanDanB.DataBean> dataBeans = new ArrayList<>();
        //A
        data.get_widget_1689825348641().forEach(e->{
            PdmBanDanB.DataBean dataBean = buildBBaseBean(data);
            for (BanDanB value : BanDanB.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getA(),e,value.getType());
                } catch (Exception ex) {
                    System.out.println(1);
                }
            }
            dataBean.set_widget_1696422046832(getParaMap(e.get_widget_1692526054993().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId1(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1710302538619(getParaMap("否"));
            //设计师
            dataBean.set_widget_1699611501516(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //供应商账号
            dataBean.set_widget_1699611288996(getParaMap(Optional.ofNullable(e.get_widget_1699611698889()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //采购责任人
            dataBean.set_widget_1696422046830(getParaMap(Optional.ofNullable(e.get_widget_1696423628948()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        //B
        data.get_widget_1692527689426().forEach(e->{
            PdmBanDanB.DataBean dataBean = buildBBaseBean(data);
            for (BanDanB value : BanDanB.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getB(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1696422046832(getParaMap(e.get_widget_1692527689436().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId1(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            //设计师
            dataBean.set_widget_1699611501516(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //供应商账号
            dataBean.set_widget_1699611288996(getParaMap(Optional.ofNullable(e.get_widget_1699611698890()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //采购责任人
            dataBean.set_widget_1696422046830(getParaMap(Optional.ofNullable(e.get_widget_1696423628957()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));

            dataBeans.add(dataBean);
        });
        //C
        data.get_widget_1692856726767().forEach(e->{
            PdmBanDanB.DataBean dataBean = buildBBaseBean(data);
            for (BanDanB value : BanDanB.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getC(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1696422046832(getParaMap(e.get_widget_1692856726777().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId1(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            //设计师
            dataBean.set_widget_1699611501516(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //供应商账号
            dataBean.set_widget_1699611288996(getParaMap(Optional.ofNullable(e.get_widget_1699611698891()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //采购责任人
            dataBean.set_widget_1696422046830(getParaMap(Optional.ofNullable(e.get_widget_1696423628959()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));

            dataBeans.add(dataBean);
        });
        //D
        data.get_widget_1692856726792().forEach(e->{
            PdmBanDanB.DataBean dataBean = buildBBaseBean(data);
            for (BanDanB value : BanDanB.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getD(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1696422046832(getParaMap(e.get_widget_1692856726802().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId1(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            //设计师
            dataBean.set_widget_1699611501516(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //供应商账号
            dataBean.set_widget_1699611288996(getParaMap(Optional.ofNullable(e.get_widget_1699611698892()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //采购责任人
            dataBean.set_widget_1696422046830(getParaMap(Optional.ofNullable(e.get_widget_1696423628961()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        //E
        data.get_widget_1692856726817().forEach(e->{
            PdmBanDanB.DataBean dataBean = buildBBaseBean(data);
            for (BanDanB value : BanDanB.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getE(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1696422046832(getParaMap(e.get_widget_1692856726827().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId1(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            //设计师
            dataBean.set_widget_1699611501516(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //供应商账号
            dataBean.set_widget_1699611288996(getParaMap(Optional.ofNullable(e.get_widget_1699611698893()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //采购责任人
            dataBean.set_widget_1696422046830(getParaMap(Optional.ofNullable(e.get_widget_1696423628963()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        //F
        data.get_widget_1692856726842().forEach(e->{
            PdmBanDanB.DataBean dataBean = buildBBaseBean(data);
            for (BanDanB value : BanDanB.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getF(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1696422046832(getParaMap(e.get_widget_1692856726852().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId1(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            //设计师
            dataBean.set_widget_1699611501516(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //供应商账号
            dataBean.set_widget_1699611288996(getParaMap(Optional.ofNullable(e.get_widget_1699611698894()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //采购责任人
            dataBean.set_widget_1696422046830(getParaMap(Optional.ofNullable(e.get_widget_1696423628965()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });

        //G
        data.get_widget_1692856726867().forEach(e->{
            PdmBanDanB.DataBean dataBean = buildBBaseBean(data);
            for (BanDanB value : BanDanB.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getG(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1696422046832(getParaMap(e.get_widget_1692856726877().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId1(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            //设计师
            dataBean.set_widget_1699611501516(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //供应商账号
            dataBean.set_widget_1699611288996(getParaMap(Optional.ofNullable(e.get_widget_1699611698895()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            //采购责任人
            dataBean.set_widget_1696422046830(getParaMap(Optional.ofNullable(e.get_widget_1696423628967()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        return dataBeans;
    }

    private List<com.jboost.modules.app.dto.PdmBanDanC.DataBean> buildC(com.jboost.modules.app.dto.DpBanDan.DataBean data) throws Exception{
         List<PdmBanDanC.DataBean> dataBeans = new ArrayList<>();
         //A
        data.get_widget_1689825348641().forEach(e->{
            PdmBanDanC.DataBean dataBean = buildBaseBean(data);
            for (BanDanC value : BanDanC.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getA(),e,value.getType());
                } catch (Exception ex) {
System.out.println(1);
                }
            }
            dataBean.set_widget_1695299408487(getParaMap(e.get_widget_1692526054993().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1695396747262(getParaMap(1));
            dataBean.set_widget_1695648087359(getParaMap("辅助"));
            dataBean.set_widget_1699847126408(getParaMap(Optional.ofNullable(e.get_widget_1699611698889()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBean.set_widget_1700298112947(getParaMap("辅助"));
            dataBean.set_widget_1704618054087(getParaMap(Optional.ofNullable(e.get_widget_1696423628948()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
       //B
        data.get_widget_1692527689426().forEach(e->{
            PdmBanDanC.DataBean dataBean = buildBaseBean(data);
            for (BanDanC value : BanDanC.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getB(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1695299408487(getParaMap(e.get_widget_1692527689436().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1695396747262(getParaMap(1));
            dataBean.set_widget_1695648087359(getParaMap("辅助"));
            dataBean.set_widget_1699847126408(getParaMap(Optional.ofNullable(e.get_widget_1699611698890()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBean.set_widget_1700298112947(getParaMap("辅助"));
            dataBean.set_widget_1704618054087(getParaMap(Optional.ofNullable(e.get_widget_1696423628957()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        //C
        data.get_widget_1692856726767().forEach(e->{
            PdmBanDanC.DataBean dataBean = buildBaseBean(data);
            for (BanDanC value : BanDanC.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getC(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1695299408487(getParaMap(e.get_widget_1692856726777().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1699847126408(getParaMap(Optional.ofNullable(e.get_widget_1699611698891()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBean.set_widget_1695396747262(getParaMap(1));
            dataBean.set_widget_1695648087359(getParaMap("辅助"));
            dataBean.set_widget_1700298112947(getParaMap("辅助"));
            dataBean.set_widget_1704618054087(getParaMap(Optional.ofNullable(e.get_widget_1696423628959()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        //D
        data.get_widget_1692856726792().forEach(e->{
            PdmBanDanC.DataBean dataBean = buildBaseBean(data);
            for (BanDanC value : BanDanC.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getD(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1695299408487(getParaMap(e.get_widget_1692856726802().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1699847126408(getParaMap(Optional.ofNullable(e.get_widget_1699611698892()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBean.set_widget_1695396747262(getParaMap(1));
            dataBean.set_widget_1695648087359(getParaMap("辅助"));
            dataBean.set_widget_1700298112947(getParaMap("辅助"));
            dataBean.set_widget_1704618054087(getParaMap(Optional.ofNullable(e.get_widget_1696423628961()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        //E
        data.get_widget_1692856726817().forEach(e->{
            PdmBanDanC.DataBean dataBean = buildBaseBean(data);
            for (BanDanC value : BanDanC.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getE(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1695299408487(getParaMap(e.get_widget_1692856726827().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1699847126408(getParaMap(Optional.ofNullable(e.get_widget_1699611698893()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBean.set_widget_1695396747262(getParaMap(1));
            dataBean.set_widget_1695648087359(getParaMap("辅助"));
            dataBean.set_widget_1700298112947(getParaMap("辅助"));
            dataBean.set_widget_1704618054087(getParaMap(Optional.ofNullable(e.get_widget_1696423628963()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        //F
        data.get_widget_1692856726842().forEach(e->{
            PdmBanDanC.DataBean dataBean = buildBaseBean(data);
            for (BanDanC value : BanDanC.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getF(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1695299408487(getParaMap(e.get_widget_1692856726852().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1695396747262(getParaMap(1));
            dataBean.set_widget_1695648087359(getParaMap("辅助"));
            dataBean.set_widget_1699847126408(getParaMap(Optional.ofNullable(e.get_widget_1699611698894()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBean.set_widget_1700298112947(getParaMap("辅助"));
            dataBean.set_widget_1704618054087(getParaMap(Optional.ofNullable(e.get_widget_1696423628965()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });

        //G
        data.get_widget_1692856726867().forEach(e->{
            PdmBanDanC.DataBean dataBean = buildBaseBean(data);
            for (BanDanC value : BanDanC.values()) {
                try {
                    RefelctUtils.copy(dataBean,value.getG(),e,value.getType());
                } catch (Exception ex) {

                }
            }
            dataBean.set_widget_1695299408487(getParaMap(e.get_widget_1692856726877().stream().map(e1->{
                try {
                    return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
                } catch (IOException ex) {

                };
                return "";
            }).collect(Collectors.toList())));
            dataBean.set_widget_1695396747262(getParaMap(1));
            dataBean.set_widget_1695648087359(getParaMap("辅助"));
            dataBean.set_widget_1699847126408(getParaMap(Optional.ofNullable(e.get_widget_1699611698895()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBean.set_widget_1700298112947(getParaMap("辅助"));
            dataBean.set_widget_1704618054087(getParaMap(Optional.ofNullable(e.get_widget_1696423628967()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
            dataBeans.add(dataBean);
        });
        return dataBeans;

    }


    private PdmBanDanB.DataBean buildBBaseBean(com.jboost.modules.app.dto.DpBanDan.DataBean data) {
        PdmBanDanB.DataBean dataBean = new PdmBanDanB.DataBean();
        dataBean.set_widget_1695639042033(getParaMap(data.get_widget_1692338476272()));
        dataBean.set_widget_1696422046835(getParaMap(data.get_widget_1689821813928()));
        dataBean.set_widget_1695639042032(getParaMap("辅助"));
        dataBean.set_widget_1710486140422(getParaMap("是"));
        dataBean.set_widget_1710302538619(getParaMap("否"));
        dataBean.set_widget_1695639321594(getParaMap("正常开发"));
        dataBean.set_widget_1699846782002(getParaMap(data.getStyle_number()));
        return dataBean;
    }

    private PdmBanDanC.DataBean buildBaseBean(com.jboost.modules.app.dto.DpBanDan.DataBean data) {
        PdmBanDanC.DataBean dataBean = new PdmBanDanC.DataBean();
        dataBean.set_widget_1692338476271(getParaMap("辅助"));
        dataBean.set_widget_1695299408499(getParaMap(data.get_widget_1689772437724()));
        dataBean.set_widget_1692338476272(getParaMap(data.get_widget_1692338476272()));
        dataBean.set_widget_1687311922144(getParaMap(data.get_widget_1687311922144()));
        dataBean.set_widget_1689820883385(getParaMap(data.get_widget_1689820883385().getUsername()));
        dataBean.set_widget_1692338476270(getParaMap(data.get_widget_1689821813937()));
        dataBean.setStyle_number(getParaMap(data.getStyle_number()));
        dataBean.set_widget_1689822029731(getParaMap(data.get_widget_1689822029731()));
        dataBean.set_widget_1689821813925(getParaMap(data.get_widget_1689821813925()));
        dataBean.set_widget_1689821813926(getParaMap(data.get_widget_1689821813926()));
        dataBean.set_widget_1689821813927(getParaMap(data.get_widget_1689821813927()));
        dataBean.set_widget_1689821813928(getParaMap(data.get_widget_1689821813928()));
        dataBean.set_widget_1689821813929(getParaMap(data.get_widget_1689821813929()));
        dataBean.set_widget_1692338476270(getParaMap(data.get_widget_1689821813937()));
        dataBean.set_widget_1689821813930(getParaMap(data.get_widget_1689821813930()));
        dataBean.set_widget_1689821813931(getParaMap(data.get_widget_1689821813931()));
        dataBean.set_widget_1689821813932(getParaMap(data.get_widget_1689821813932()));
        dataBean.set_widget_1689821813933(getParaMap(data.get_widget_1689821813933()));
        dataBean.set_widget_1695300314310(getParaMap("正常"));
        dataBean.set_widget_1689821813935(getParaMap(data.get_widget_1689821813935()));
        dataBean.set_widget_1692353365151(getParaMap(data.get_widget_1692353365151()));
        dataBean.set_widget_1692919566102(getParaMap(data.get_widget_1692919566102().stream().map(e1->{
            try {
                return JdyFileUtils.upload(getAppId(),getFormId2(),e1.getUrl(),getJdyHeaders());
            } catch (IOException ex) {

            };
            return "";
        }).collect(Collectors.toList())));
        //效果图
//        dataBean.set_widget_1692919566102(getParaMap(data.get_widget_1689821813937()));
        //dataBean.set_widget_1689821813931(getParaMap(data.get_widget_1689822029731()));
        dataBean.set_widget_1689821813932(getParaMap(data.get_widget_1689821813932()));
        dataBean.set_widget_1689821813933(getParaMap(data.get_widget_1689821813933()));
        dataBean.set_widget_1689820883385(getParaMap(Optional.ofNullable(data.get_widget_1689820883385()).orElse(new com.jboost.modules.app.dto.DpBanDan.DataBean.CreatorBean()).getUsername()));
        return dataBean;
    }

    public String jdyUpdate(String data_id,Object data) throws IOException {
        HashMap<String, Object> param = getParam();
        param.put("entry_id",getFormId1());
        param.put("data_id", data_id);
        param.put("data", data);
        if (Objects.nonNull(UUIDS.get())){
            param.put("transaction_id", UUIDS.get());
        }
        String post = HttpRestUtils.post(update_api , param, getJdyHeaders());
        return post;
    }

    public String jdyUpdate2(String data_id,Object data) throws IOException {
        HashMap<String, Object> param = getParam();
        param.put("entry_id",getFormId2());
        param.put("data_id", data_id);
        param.put("data", data);
        if (Objects.nonNull(UUIDS.get())){
            param.put("transaction_id", UUIDS.get());
        }
        String post = HttpRestUtils.post(update_api , param, getJdyHeaders());
        return post;
    }


    public void sync2() throws IOException {
        log.info("开始批量查询Hs材料数据");
        

    }
    public void sync1() throws IOException {
        log.info("开始批量查询Hs材料数据");

}



}
